﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using System.Reflection;
using Cn.Cellula.Model;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Edwon.Web.Validation;
using Cn.Edwon.Web;
using Cn.Cellula.Biz;
using Cn.Cellula.Model.System;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Db.Module {
    public partial class Edit : PageSupport {
        String EOKey = null;
        IUserBiz biz = BizFactory.Get<IUserBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            EOKey = Request.QueryString["id"];
            if (!Page.IsPostBack) {
                InitForm();
                if (!String.IsNullOrEmpty(EOKey)) {
                    FillForm(EOKey);
                }
            }
        }

        void InitForm() {
        }
        void FillForm(String key) {
            TSysModuleEO eo = biz.Load<TSysModuleEO>(key);
            this.txt_ModuleKey.Text = eo.ModuleKey;
            this.txt_ModuleKey.Enabled = false;
            this.txt_ModuleName.Text = eo.ModuleName;
            this.txt_PkName.Text = eo.PkName;
            this.txt_TableName.Text = eo.TableName;
        }

        protected void btn_save_Click(object sender, EventArgs e) {
            bool bk = QuickValidator.Execute(Request, this.txt_ModuleKey.Parent);
            if (!bk) {
                SiteInfo.Send(Page, TxtDef.ERROR, QuickValidator.Message);
                return;
            }
            try {
                if (String.IsNullOrEmpty(EOKey)) {
                    TSysModuleEO eo = new TSysModuleEO();
                    eo.ModuleKey = this.txt_ModuleKey.Text;
                    eo.ModuleName = this.txt_ModuleName.Text;
                    eo.PkName = this.txt_PkName.Text;
                    eo.TableName = this.txt_TableName.Text;
                    biz.Save<TSysModuleEO>(eo);
                    BizFactory.Get<ILogBiz>().LogInsert("系统模块", eo.ModuleName, this.Actor, Request);
                } else {
                    TSysModuleEO eo = biz.Load<TSysModuleEO>(EOKey);
                    eo.ModuleName = this.txt_ModuleName.Text;
                    eo.PkName = this.txt_PkName.Text;
                    eo.TableName = this.txt_TableName.Text;
                    biz.Update<TSysModuleEO>(eo);
                    BizFactory.Get<ILogBiz>().LogUpdate("系统模块", eo.ModuleName, this.Actor, Request);
                }
                Response.Redirect("List.aspx");
            } catch (Exception ex) {
                SiteInfo.Send(Page, TxtDef.ERROR, ex.Message);
            }
        }

    }
}
